

let index
//二分查找法
function eff(arr,l,r,tar){
   if(l>r) return index=-1

   let mid=l+(~~((r-l)/2))

   if(arr[mid]==tar){
       index=mid
       return index
   }else if(arr[mid]<tar){
       eff(arr,mid+1,r,tar)
   }else{
       eff(arr,l,mid-1,tar)
   }
}

let arr=[1,2,3,4,5,6,7,8,9]
let res=eff(arr,0,arr.length-1,7)
console.log(index)


